package test;

import java.util.Scanner;

public class Ch {
    public static void main(String[] args) {
        final int Len=10;
        Scanner in=new Scanner(System.in);
        String[] caidan=new String[]{"鱼香肉丝","红烧带鱼","红烧肉","肉末茄子","时令蔬菜","拍黄瓜"};
        int xiaog=1,count1=0;
        int[] xuhao=new int[Len],jiage=new int[]{28,58,98,28,18,12},dianzan=new int[6],riqi=new int[Len];
        String[] name=new String[Len],cai=new String[Len],dizhi=new String[Len],zhuangtai=new String[Len];
        double[] qian=new double[Len];
        wai:
        while (true) {
            System.out.println("*******吃货联盟订餐系统********");
            System.out.println("      1、我要订餐");
            System.out.println("      2、查看餐袋");
            System.out.println("      3、签收订单");
            System.out.println("      4、删除订单");
            System.out.println("      5、我要点赞");
            System.out.println("      6、退出系统");
            System.out.print("\n请输入功能序号：");
            while ((xiaog = in.nextInt())<1||xiaog>6){
                System.out.print("输入错误请重新输入：");
            }
            switch (xiaog) {
                case 1: {
                    System.out.println("*******吃货联盟订餐系统********");
                    for (int i = 0; i < caidan.length; i++) {
                        System.out.print(i+1+"、");
                        System.out.print(caidan[i]);
                        System.out.print("    " + jiage[i]+"元");
                        System.out.println("   点赞数"+dianzan[i]);
                    }
                    System.out.print("输入菜品序号：");
                    int caiping=0;
                    while ((caiping=in.nextInt())<1||caiping>caidan.length) {
                        System.out.print("没有找到菜品请从新输入：");
                    }
                    cai[count1]=caidan[caiping-1];
                    System.out.print("请输入姓名：");
                    name[count1]=in.next();
                    System.out.print("请输入份数：");
                    int a=in.nextInt();
                    cai[count1]=caidan[caiping-1]+a+"份";
                    System.out.print("请输入送餐时间（10点-12点）：");
                    int sj=0;
                    while (true){
                        sj=in.nextInt();
                        if(sj>=10 && sj<=12) break ;
                        System.out.print("时间错误重新输入：");
                    }
                    riqi[count1]=sj;
                    System.out.print("请输入地址：");
                    dizhi[count1]=in.next();
                    qian[count1]=jiage[caiping-1]*a;
                    zhuangtai[count1]="已预定";
                    count1++;
                    if(count1>=9){
                        System.out.println("*******餐袋已满，订餐失败********");
                        count1--;
                    }else{
                        double peisong=0;
                        if(qian[count1-1]<50) {
                            qian[count1-1]+=5;
                            peisong=5;
                        };
                        System.out.println("总金额"+qian[count1-1]+"\t包含配送费："+peisong);
                        System.out.println("*******成功订餐********");
                    }
                    System.out.print("输入0返回：");
                    int c=1;
                    while (true){
                        c=in.nextInt();
                        if(c==0){
                            break ;
                        }
                        System.out.print("输入错误重新输入：");
                    }
                    break;
                }
                case 2:{
                    System.out.println("*******餐袋********");
                    System.out.println("序号    订餐人    餐品信息       送餐日期     送餐地址    总金额      订单状态");
                    for(int i=0;i<count1;i++){
                        System.out.print(i+1+"\t\t");
                        System.out.print(name[i]+"\t\t");
                        System.out.print(cai[i]+"\t\t");
                        System.out.print(riqi[i]+"\t\t");
                        System.out.print(dizhi[i]+"\t\t");
                        System.out.print(qian[i]+"\t\t");
                        System.out.println(zhuangtai[i]+"\t\t");
                    }
                    double zong=0;
                    for(int i=0;i<qian.length;i++){
                        zong+=qian[i];
                    }
                    System.out.println("总金额："+zong+"\t");
                    System.out.print("输入0返回：");
                    int c=1;
                    while (true){
                        c=in.nextInt();
                        if(c==0){
                            break ;
                        }
                        System.out.print("输入错误重新输入：");
                    }
                    break;
                }
                case 3:{
                    int b=0;
                    System.out.print("请输入订单序号：");
                    while (true) {
                        b= in.nextInt();
                        if(b>0 && b<=count1) break;
                        System.out.print("没有找到订单号请从新输入：");
                    }
                    System.out.println("是否签收订单（Y/N）");
                    char a;
                    for( ; ;) {
                        a = in.next().charAt(0);
                        if(a=='n') a='N';
                        if(a=='y') a='Y';
                        if (a=='Y') {
                            zhuangtai[b-1]="已签收";
                            System.out.println("已签收");
                            break;
                        }
                        else if(a=='N'){
                            System.out.println("取消签收");
                            break ;
                        }
                        else{
                            System.out.print("输入有误请重新输入：");
                        }
                    }
                    System.out.print("输入0返回：");
                    int c=1;
                    while (true){
                        c=in.nextInt();
                        if(c==0){
                            break ;
                        }
                        System.out.print("输入错误重新输入：");
                    }
                    break;
                }
                case 4:{
                    int b=0;
                    System.out.print("请输入订单序号：");
                    //while (true) {
                        b= in.nextInt();
                        if((b<1 || b>count1) || zhuangtai[b - 1].equals("已预定")) {
                            System.out.println("没有找到订单号或者该订单已签收请从新输入：");
                            continue;
                        }

                    //}
                    for(int i=b-1;i<name.length-1;i++){
                        name[i]=name[i+1];
                        cai[i]=cai[i+1];
                        dizhi[i]=dizhi[i+1];
                        qian[i]=qian[i+1];
                        riqi[i]=riqi[i+1];
                        zhuangtai[i]=zhuangtai[i+1];
                    }
                    count1--;
                    System.out.println("*******成功删除********");
                    System.out.print("输入0返回：");
                    int c=1;
                    while (true){
                        c=in.nextInt();
                        if(c==0){
                            break ;
                        }
                        System.out.print("输入错误重新输入：");
                    }
                    break;
                }
                case 5:{
                    System.out.print("请输入点赞菜品的序号：");
                    int zan;
                    while (true) {
                        zan=in.nextInt();
                        if(zan>0 && zan<=6) break;
                        System.out.print("没有找到菜品请从新输入：");
                    }
                    System.out.println("*****点赞成功******");
                    dianzan[zan-1]+=1;
                    System.out.print("输入0返回：");
                    int c=1;
                    while (true){
                        c=in.nextInt();
                        if(c==0){
                            break ;
                        }
                        System.out.print("输入错误重新输入：");
                    }
                    break ;
                }
                case 6:{
                    System.out.println("是否确定退出（Y/N）");
                    char a;
                    for( ; ;) {
                        a = in.next().charAt(0);
                        if(a=='n') a='N';
                        if(a=='y') a='Y';
                        if (a=='Y') {
                            break wai;
                        }
                        else if(a=='N'){
                            continue wai;
                        }
                        else {
                            System.out.print("输入有误请重新输入：");
                        }
                    }
                }
            }
        }
    }
}
